/*
  Copyright (C) 2011, Kyungjoo Kim
  
  This file is part of UHM (Unassembled HyperMatrix) sparse direct solver.
  
  All rights reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  Also add information on how to contact you by electronic and paper mail.
  
  
  Kyungjoo Kim
  iamkyungjoo@gmail.com
*/
#include "uhm/common.hxx"
#include "uhm/const.hxx"
#include "uhm/util.hxx"

#include "uhm/object.hxx"

#include "uhm/operation/scheduler.hxx"
#include "uhm/operation/element.hxx"

#include "uhm/mesh/node.hxx"
#include "uhm/mesh/element.hxx"

#include "uhm/matrix/uhm/matrix.hxx"

#include "uhm/mesh/mesh.hxx"



namespace uhm {
  // --------------------------------------------------------------
  // ** LU nopiv
  /*
  void Mesh_::export_graphviz_lu_nopiv(char *full_path, int bmn) {

    FILE *fp;
    assert(open_file(full_path, "w", &fp));
    linal::head_graphviz(fp, "Mesh_tasks");

    int start=0, end=0;
    std::map< int, Element_ >::iterator it;
    for (it=this->elements.begin();it!=this->elements.end();++it) {
      it->second.write_lu_nopiv(fp, bmn, start, end);
      start = end;
    }

    for (it=this->elements.begin();it!=this->elements.end();++it) {
      Element e = &(it->second);
      if (!e->is_orphan())
	fprintf(fp, "%d -> {%d;};\n", 
		e->get_marker(1),e->get_parent()->get_marker(0));
    }

    linal::tail_graphviz(fp);
    assert(close_file(fp));
  }
  
  void Element_::write_lu_nopiv(FILE *fp, int bmn, int &start, int &end) {
    
    // write on the file
    linal::Flat_ fA;
    linal::Hier_ hA;

    std::pair<int,int> n_dof = this->get_n_dof();
    int m   = n_dof.first + n_dof.second;
    fA.create(LINAL_REAL, m, m);
    hA.create(fA, bmn, bmn);
    
    linal::lu_nopiv(fp, start, end, hA);

    printf("start %d, end %d\n", start, end-1);
    this->set_marker(0,start);
    this->set_marker(1,end-1);

    fA.free();
    hA.free();
  }
  */
}
